package com.silp.labs.cacticlient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;




import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class CactiClientActivity extends Activity {


	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

	}

	public void clickme(View v) {
		switch (v.getId()) {
		case R.id.button2:
			try {
				String send_result =Sendrequest.sendgetTree("lamphusi");
				Intent treeIntent =new Intent(getApplicationContext(),Treedata_Listview.class);
				treeIntent.putExtra("treedata", send_result);
				//treeIntent.put
				startActivity(treeIntent);
				
				/*TreeData[] treedata = new TreeData[100];
				int ntreelenght = 0;
				ntreelenght = ProcessData.ProcessDataTree(send_result, treedata, ntreelenght);*/
				
				/*String[] aa = TreeData.getTreeListName(treedata, ntreelenght);
				for (int i = 0; i < aa.length; i++) {
					String string = aa[i];
					Toast.makeText(getApplicationContext(), string, 100).show();
				}*/
				//for (int i = 0; i < lines.length; i++) {


			} catch (SoapFault e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			break;

		case R.id.button3:
			/*try {


					Bitmap send_result =Sendrequest.sendgetGraph("lamphusi", 71,1330107957 ,1330170213 , 5,500);
					ImageView imv = (ImageView)findViewById(R.id.imageView1);

					imv.setImageBitmap(send_result);

				} catch (SoapFault e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}*/

			Intent mIntent = new Intent(getApplicationContext(), ShowGraph.class);
			startActivity(mIntent);
			break;
		case R.id.button1:
			try {
				String send_result = Sendrequest.sendgetDownHosts("lamphusi");
				String[] lines = send_result.split("\n");

				for (int i = 0; i < lines.length; i++) {
					String string = lines[i];
					StringTokenizer mtokens= new StringTokenizer(string,";");
					String hostid = mtokens.nextToken();
					String host_ip = mtokens.nextToken();
					String host_des = mtokens.nextToken();

					Toast.makeText(getApplicationContext(), "Hostname "+host_des+" with IP "+host_ip+" and id is "+hostid+" down !!!", 100).show();

				}
			} catch (SoapFault e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			break;

		default:
			break;
		}

	}


}




